package tinybase.rm;

import java.nio.ByteBuffer;

public class RM_FileHdr {
	private int firstFree; // first free page in the linked list
	private int recordSize; // fixed record size
	private int numRecordsPerPage; // # of records in each page
	private int pageHeaderSize; // page header size
	private int numRecords; // # of pages in the file

	public byte[] toBytes() {
		byte[] arr= new byte[RM_Internal.RM_FILEHDR_SIZE];
		ByteBuffer buf= ByteBuffer.wrap(arr);
		buf.putInt(0, firstFree);
		buf.putInt(4, recordSize);
		buf.putInt(8, numRecordsPerPage);
		buf.putInt(12, pageHeaderSize);
		buf.putInt(16, numRecords);
		return arr;
	}
	
	
	public void copyFromBytes(byte[] data, int offset) {
		ByteBuffer buf = ByteBuffer.wrap(data);
		firstFree = buf.getInt(offset);
		recordSize = buf.getInt(offset + 4);
		numRecordsPerPage = buf.getInt(offset + 8);
		pageHeaderSize = buf.getInt(offset + 12);
		numRecords = buf.getInt(offset + 16);
	}
	
	public RM_FileHdr() {
		firstFree = 0;
		recordSize = 0;
		numRecordsPerPage = 0;
		pageHeaderSize = 0;
		numRecords = 0;
	}
	
	public void setFirstFree(int firstFree) {
		this.firstFree = firstFree;
	}
	
	public int getFirstFree() {
		return firstFree;
	}

	public void setRecordSize(int recordSize) {
		this.recordSize = recordSize;
	}
	
	public int getRecordSize() {
		return recordSize;
	}

	public void setNumRecordsPerPage(int numRecordsPerPage) {
		this.numRecordsPerPage = numRecordsPerPage;
	}

	public int getNumRecordsPerPage() {
		return this.numRecordsPerPage;
	}
	
	public void setPageHeaderSize(int pageHeaderSize) {
		this.pageHeaderSize = pageHeaderSize;
	}
	
	public int getPageHeaderSize() {
		return pageHeaderSize;
	}

	public void setNumRecords(int numRecords) {
		this.numRecords = numRecords;
	}
	
	public int getNumRecords() {
		return numRecords;
	}

}
